<?php
	require_once("conexion/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Formulario PSMB</title>
<link href="Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />
<link href="Estilos/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

<script src="include_js/jquery.js" type="text/javascript"></script>

<style>
.texto
{
	font-size:14px;
	margin-left:10px;
	font:Verdana, Arial, Helvetica, sans-serif; 
	color:#0066CC;
}
.borde
{
	/*border:0px solid #6593C0;*/
	border:1px solid #D3E4E5;
}
.asterisco
{
	color:#0000FF;
	font-weight:bold;
}
</style>
<script>
function BorraDatos(dato)
{
	var cadena = dato.substring(8,9);
    if(cadena=='1')
	{
		document.getElementById("txtENombre").value= "";
		document.getElementById('txtERut').value = "";
		document.getElementById('txtEComuna').value = "";
		document.getElementById("txtEFono").value = "";
		document.getElementById("txtEFax").value = "";
		document.getElementById("txtEDir").value = "";
		document.getElementById("txtEGiro").value = "";
		document.getElementById("txtERSocial").value = "";
		
		document.getElementById("txtDNombre").value = "";
		document.getElementById("txtDRut").value = "";
		document.getElementById('cmb_Region').value=10;
		document.getElementById("txtDComuna").value = "";
		document.getElementById("txtDDir").value = "";
		
		document.getElementById("txtNumBoleta").value = "";
		document.getElementById("txtGlosa").value = "";
		document.getElementById("txtTotal").value = "";
		document.getElementById("txtImpuesto").value = "";
		document.getElementById('txtFecha').value="";		
		Foco();
	}
}

function EliminaPuntos(num)
{
	valor = num.replace(/\./g,'');
	return valor;
}

function validar(e)
{ 
    tecla = (document.all) ? e.keyCode : e.which; 
    if (tecla==8) return true; //Tecla de retroceso (para poder borrar) 
    patron = /\d/;
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
} 

function puntitos(donde,caracter)
{
	pat = /[\*,\+,\(,\),\?,\,$,\[,\],\^]/;
	valor = donde.value;
	largo = valor.length;
	crtr = true;
	if(isNaN(caracter) || pat.test(caracter) == true)
	{
		if (pat.test(caracter)==true)
		{ 
			caracter = "\"" + caracter;
		}
		carcter = new RegExp(caracter,"g");
		valor = valor.replace(carcter,"");
		donde.value = valor;
		crtr = false;
	}
	else
	{
		var nums = new Array();
		cont = 0;
		for(m=0;m<largo;m++)
		{
			if(valor.charAt(m) == "." || valor.charAt(m) == " ")
				{continue;}
			else
			{
				nums[cont] = valor.charAt(m);
				cont++;
			}
		}
	}
	var cad1="",cad2="",tres=0;
	if(largo > 3 && crtr == true)
	{
		for (k=nums.length-1;k>=0;k--)
		{
			cad1 = nums[k];
			cad2 = cad1 + cad2;
			tres++;
			if((tres%3) == 0)
			{
				if(k!=0)
				{
					cad2 = "." + cad2;
				}
			}
		}
		donde.value = cad2;
	}
}

function ObtieneTotal(valor1,valor2)
{
	cantidad = document.getElementById(valor1).value;
	if(cantidad!="")
	{
		cantidad = EliminaPuntos(cantidad);
		total = (cantidad*0.10);
		txt = document.getElementById(valor2);
		document.getElementById(valor2).value = total;
		puntitos(txt,total);
	}
}

function Foco()
{
	document.getElementById('txtENombre').focus();
}
</script>
</head>
<body onload="Foco();">
<form name="form_Honorario" id="form_Honorario" method="post">
<div class='option2'><label style="font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;">Secci&oacute;n de Honorarios.</label></div>
<div class='groupbox'>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="uno">
<tr>
  <td class="borde" colspan="2"><div style="float:left; clear:none; margin-left:10px; margin-top:5px;"><label style="color:#0000FF; font-size:12px; font-weight:bold;">Datos Obligatorios(*)</label></div></td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
</tr>
<tr>
  <td class="borde" colspan="4"><hr /></td>
</tr>
<tr>
  <td class="borde" colspan="2"><label class="texto" style="font-weight:bold;">Datos del Emisor.</label></td>
  <td width="7%" class="borde">&nbsp;</td>
  <td width="35%" class="borde">&nbsp;</td>
  </tr>
<tr>
  <td width="20%" class="borde">&nbsp;</td>
  <td width="38%" class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
</tr>
<tr>
	<td class="borde"><label class="texto" style="margin-left:35px;">Nombre:</label>&nbsp;</td>
	<td class="borde"><input type="text" name="txtENombre" size="40"/>&nbsp;<label class="asterisco">*</label></td>
	<td class="borde"><label class="texto">Fono:</label></td>
	<td class="borde"><input name="txtEFono" type="text" size="16" /></td>
	</tr>
<tr>
  <td class="borde"><label class="texto" style="margin-left:35px;">Rut:</label></td>
  <td class="borde"><input type="text" name="txtERut" />&nbsp;<label class="asterisco">*</label>&nbsp;&nbsp;<label style="font-size:11px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#0000FF;">Ej:(14234123-3)</label></td>
  <td class="borde"><label class="texto">Fax:</label></td>
  <td class="borde"><input name="txtEFax" type="text" size="16" /></td>
</tr>
<tr>
  <td class="borde"><label class="texto" style="margin-left:35px;">Comuna:</label></td>
  <td class="borde"><input type="text" name="txtEComuna" /></td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
</tr>
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Direcci&oacute;n:</label></td>
	  <td class="borde" colspan="3"><input name="txtEDir" type="text" size="80" /></td>
  </tr>
  
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Giro:</label>&nbsp;</td>
    <td class="borde" colspan="3"><input type="text" name="txtEGiro" size="80"/>&nbsp;<label class="asterisco">*</label></td>
    </tr>
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Raz&oacute;n Social:</label></td>
    <td class="borde" colspan="3"><input name="txtERSocial" type="text" size="80" />&nbsp;<label class="asterisco">*</label></td>
    </tr>
  <tr>
    <td class="borde" colspan="4"><hr /></td>
  </tr>
  <tr>
    <td class="borde"colspan="2"><label class="texto" style="font-weight:bold;">Datos del Destinatario.</label></td>
	<td class="borde">&nbsp;</td>
	<td class="borde">&nbsp;</td>
  </tr>
  <tr>
    <td class="borde">&nbsp;</td>
    <td class="borde">&nbsp;</td>
	<td class="borde">&nbsp;</td>
	<td class="borde">&nbsp;</td>
  </tr>
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Nombre:</label></td>
    <td class="borde"><input type="text" name="txtDNombre" size="40" value="FISHING PARTNERS LTDA"/>
      &nbsp;
      <label class="asterisco">*</label></td><td class="borde">&nbsp;</td>
	<td class="borde">&nbsp;</td>
  </tr>
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Rut:</label></td>
    <td class="borde"><input type="text" name="txtDRut" value="77987930-5" />&nbsp;<label class="asterisco">*</label>&nbsp;&nbsp;<label style="font-size:11px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#0000FF;">Ej:(14234123-3)</label></td>
	<td class="borde">&nbsp;</td>
	<td class="borde">&nbsp;</td>
  </tr>
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Regi&oacute;n:</label></td>
    <td class="borde" colspan="3"><select name="cmb_Region">
      <option value="10">X LOS LAGOS</option>
      <?php
				$con = new Conexion();
        		$con2 = $con->conexionBD("fpproduccion");
                $sql = "select RegCod,RegNombre from region";
                $resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
				while ($row = mysql_fetch_row($resultado))
				{
					if($row[0]!=10)
					{
						echo "<option value='".$row[0]."'>".$row[1]."</option>";
					}
				}
                $con->cerrarBD();
	?>
    </select></td>
  </tr>
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Comuna:</label></td>
    <td class="borde"><input type="text" name="txtDComuna" value="PUERTO MONTT" /></td>
    <td class="borde">&nbsp;</td>
    <td class="borde">&nbsp;</td>
  </tr>
  <tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Direcci&oacute;n:</label></td>
	  <td class="borde" colspan="3"><input name="txtDDir" type="text" size="80" value="LAGUNAS DE VENECIA #1993" /></td>
  </tr>
  <tr>
    <td class="borde" colspan="4"><hr /></td>
  </tr>
  <tr>
    <td class="borde"colspan="2"><label class="texto" style="font-weight:bold;">Datos de la Boleta.</label></td>
    <td class="borde">&nbsp;</td>
    <td class="borde">&nbsp;</td>
  </tr>
  <tr>
    <td class="borde">&nbsp;</td>
    <td class="borde">&nbsp;</td>
    <td class="borde">&nbsp;</td>
    <td class="borde">&nbsp;</td>
  </tr>
	<tr>
		  <td class="borde"><label class="texto" style="margin-left:35px;">N&deg; Boleta:</label></td>
		  <td class="borde"><input type="text" name="txtNumBoleta" onkeypress="return validar(event)"/>&nbsp;<label class="asterisco">*</label></td>
		  <td class="borde">&nbsp;</td>
		  <td class="borde">&nbsp;</td>
	</tr>
	<tr>
	  <td class="borde"><label class="texto" style="margin-left:35px;">Fecha:</label></td>
	  <td class="borde"><input name="txtFecha" type="text" id="txtFecha" size="10">&nbsp;<img src="imagen/img.gif" width="20" height="14" title="calendario" style="cursor: pointer; border: 1px solid green;" onmouseover="this.style.background='black';" onmouseout="this.style.background=''" onclick="popUpCalendar(txtFecha, form_Honorario.txtFecha, 'dd-mm-yyyy');" />&nbsp;<label class="asterisco">*</label></td><td class="borde">&nbsp;</td>
	  <td class="borde">&nbsp;</td>
	  </tr>
	<tr>
	  <td class="borde"><label class="texto" style="margin-left:35px;">Glosa:</label></td>
	  <td class="borde" colspan="3"><textarea name="txtGlosa" cols="80" rows="3"></textarea>&nbsp;<label class="asterisco">*</label></td>
	  </tr>
	<tr>
	  <td class="borde"><label class="texto" style="margin-left:35px;">Total ($):</label></td>
	  <td class="borde"><input type="text" name="txtTotal" onkeyup="puntitos(this,this.value.charAt(this.value.length-1))" /></td>
	  <td class="borde">&nbsp;</td>
	  <td class="borde">&nbsp;</td>
	  </tr>
	<tr>
	  <td class="borde"><label class="texto" style="margin-left:35px;">10% Retenido:</label></td>
	  <td class="borde"><input type="text" name="txtImpuesto" onfocus="ObtieneTotal('txtTotal','txtImpuesto');"  /></td>
	  <td class="borde">&nbsp;</td>
	  <td class="borde">&nbsp;</td>
	  </tr>
	
  <tr>
    <td class="borde" colspan="4">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" id="TCheque" style="display:none;">
		<tr>	
			<td class="borde"><label class="texto">N&deg; Cheque:</label></td>
			<td class="borde"><input type="text" name="txtCheque" onkeypress="return validar(event)"/>&nbsp;<label class="asterisco">*</label></td>
			<td class="borde"><label class="texto">Fecha:</label></td>
			<td class="borde"><select name="cmb_Dia1" id="cmb_Dia1">
              <option value="0">DIA</option>
              <option value="01">1</option>
              <option value="02">2</option>
              <option value="03">3</option>
              <option value="04">4</option>
              <option value="05">5</option>
              <option value="06">6</option>
              <option value="07">7</option>
              <option value="08">8</option>
              <option value="09">9</option>
              <option value="10">10</option>
              <option value="11">11</option>
              <option value="12">12</option>
              <option value="13">13</option>
              <option value="14">14</option>
              <option value="15">15</option>
              <option value="16">16</option>
              <option value="17">17</option>
              <option value="18">18</option>
              <option value="19">19</option>
              <option value="20">20</option>
              <option value="21">21</option>
              <option value="22">22</option>
              <option value="23">23</option>
              <option value="24">24</option>
              <option value="25">25</option>
              <option value="26">26</option>
              <option value="27">27</option>
              <option value="28">28</option>
              <option value="29">29</option>
              <option value="30">30</option>
              <option value="31">31</option>
            </select>
			  <select name="cmb_Mes1">
                <option value="0">MES</option>
                <option value="01">Enero</option>
                <option value="02">Febrero</option>
                <option value="03">Marzo</option>
                <option value="04">Abril</option>
                <option value="05">Mayo</option>
                <option value="06">Junio</option>
                <option value="07">Julio</option>
                <option value="08">Agosto</option>
                <option value="09">Septiembre</option>
                <option value="10">Octubre</option>
                <option value="11">Noviembre</option>
                <option value="12">Diciembre</option>
              </select>
			  <select name="cmb_Agno1">
                <option value="0">A&Ntilde;O</option>
                <option value="2009">2009</option>
                <option value="2010">2010</option>
                <option value="2011">2011</option>
                <option value="2012">2012</option>
                <option value="2013">2013</option>
              </select>&nbsp;<label class="asterisco">*</label></td>
		</tr>
		<tr>	
			<td class="borde"><label class="texto">Monto($):</label></td>
			<td class="borde"><input type="text" name="txtMonto" onkeyup="puntitos(this,this.value.charAt(this.value.length-1))" />&nbsp;<label class="asterisco">*</label></td>
			<td class="borde"><label class="texto">Cuenta:</label></td>
			<td class="borde"><select name="cmb_NombreCuenta" id="cmb_NombreCuenta">
              <option value="0">--CUENTA--</option>
			  <option value="1">CUENTA BANCO CHILE</option>
			  <option value="2">CUENTA BANCO ESTADO CARDONAL</option>
			<?php
					/*$con = new Conexion();
					$con2 = $con->conexionBD("fpproduccion");
					$sql = "select CuenBCod,CuenBNombre from cuentabancaria";
					$resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
					while ($row = mysql_fetch_row($resultado))
					{
						echo "<option value='".$row[0]."'>".$row[1]."</option>";
					}
					$con->cerrarBD();*/
				?>
            </select>&nbsp;<label class="asterisco">*</label></td>
		</tr>
		<tr>
		  <td colspan="4" class="borde"><hr /></td>
		  </tr>
		</table>	</td>
  </tr>
  <tr>
    <td class="borde" colspan="4">&nbsp;</td>
  </tr> 
  <tr>
    <td class="borde" colspan="4"><div class="formtail"><div style="float:left; margin-top:5px;"><a href="#arriba">Subir</a></div><input name="btn_Guardar" id="btn_Guardar" type="button" value=" " class="guardar" /></div></td>
  </tr>
</table>
</div>
</form>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td><div id="mensaje"></div></td></tr>
</table>
</body>
<script>
$('#btn_Guardar').click(function() 
{ 
        $.ajax({
            type: 'POST',
            url: 'Contabilidad/Ingresa_Honorarios.php',
            data: $('#form_Honorario').serialize(),
            success: function(data) {
                $('#mensaje').html(data);
				BorraDatos(data);
            }
        })
});
</script>
</html>